<%-- 
    Document   : warehouse
    Created on : 20.04.2013, 22:32:42
    Author     : Yasya
--%>

<%@page import="entity.Role"%>
<%@page import="entity.Users"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<script language="Javascript">
    function editWarehouse() {
        document.getElementById("mainForm").action = "EditWarehouse";
        document.getElementById("mainForm").submit();

    }
    function refresh() {
        document.getElementById("selection").action = "ViewWarehouse";
        document.getElementById("selection").submit();
    }
    function sendSelected() {
        var optionArray = document.getElementById("sort");
        var selectedValue = document.getElementById("selectedValue").value;

        for (var c = 0; c < optionArray.length; c++) {
            if (optionArray.options[c].value == selectedValue) {
                document.getElementById("sort").options[c].selected = true;
            }
        }

    }
    function nextPage() {
        var temp = document.getElementById("pageNumber").value;
        var number = document.getElementById("numberOfPages").value;
        if (temp <= number) {
            temp++;
           
        } else {
            alert("No more information about warehouses");
        }
        document.getElementById("pageNumber").value = temp;

        document.getElementById("next").action = "ViewWarehouse";
        document.getElementById("next").submit();

    }
    function prevPage() {
        var temp = document.getElementById("pageNumber").value;

        if (temp > 1) {
            temp--;
        } else {
            temp = 1;
        }
        document.getElementById("pageNumber").value = temp;
        document.getElementById("next").action = "ViewWarehouse";
        document.getElementById("next").submit();
    }
    function isEmpty(str) {
        return (!str || 0 === str.length);
    }
</script>

<!DOCTYPE html>
<%
    Users user = (Users) session.getAttribute("user");
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/warehouse.css">
           <link rel="stylesheet" type="text/css" href="css/all.css">
        <title>Work with product</title>
    </head>
    <body onload="sendSelected()">
        <header>
            <div id ="top_name"> <a href="main.jsp"> 
                    <img src="/Delta-war/product/1.jpeg"></a> <h1> Warehouse employee</h1> </div>
          
            <div id="registr2">
                <p> <a href="user_name.jsp"><%=user.getLogin()%></a>

                    <a href="logout">LogOut</a> </p>

            </div>
            <div id="menu">
                <div id="line"> <a href="WarehouseOrders"> Orders</a> </div>
                <div id="line" style="background: #ff0000; "> <a href="ViewWarehouse"> Warehouses</a> </div>
                <div id="line"> <a href="catalog_product.jsp"> Product</a> </div>


            </div>


            <div id="user-panel">
                <%@ include file="rolefragment.jsp" %>
            </div>

        </header>

        <div id="main">

            <div id="find">  
                <form method="POST" action="ViewWarehouse"> 
                    <p>Find:
                        <input type="text" placeholder="Enter name to search" name="Find" size="30"  id="label"/>
                        <button id="go" type="submit" name="go" onclick="ViewWarehouse">Go</button> </p>

                </form>
            </div>

            <input type="hidden" name="selected" id="selectedValue" size="50" value="${selectedValue}"/>


            <div id="sorted"> 
                <form method="post" id="selection" action="ViewWarehouse">
                    <p> Sort by:  &nbsp   <select name="sort" id="sort" onchange="refresh()" > 
                            <option value="Name" >Name</option> 
                            <option value="Address">Address</option> 
                            <option value="ShipmentRate">Shipment rate</option>
                            <option value="Duration">Duration</option> 
                        </select>

                    </p>
                </form>
            </div>
            <div id="tabl">
                <form method="Get" id="mainForm"> 
                    <table> 
                        <TR>
                            <td id="check"></td>
                            <td id="head_table_first"><strong>Name</strong></td>
                            <td id="head_table_third"style=""><strong>Address</strong></td>
                            <td id="head_table_first"><strong>Shipment rate</strong></td>
                            <td id="head_table_first"><strong>Duration</strong></td>
                        </TR>
                        <c:forEach var="current" items="${WarehouseList}">
                            <TR>
                                <td id="check"><input  name="idWarehouse" type="radio" checked class="id" value="${current.getIdWarehouse()}">

                                </td>
                                <td id="colomn_first"> <c:out value="${current.getName()}"/></td>
                                <td id="colomn_third">  <c:out value="${current.getAddress()}"/></td>
                                <td id="colomn_first">  <c:out value="${current.getShipmentRate()}"/> </td>
                                <td id="colomn_first">   <c:out value="${current.getDurationKoefficient()}"/> </td>

                            </TR>
                        </c:forEach>

                    </table>
                </form>
            </div>


            <div id="line_button1"> <form  method="Post" action="add_warehouse.jsp"><button  type="submit" >Add warehouse</button> </form> </div>
            <div id="line_button1"> <button type="submit" onclick="editWarehouse()"> Edit warehouse</button> </form> </div>
            <div id="line_button1"> <button type="submit" onclick="refresh()"> Refresh</button> </div>
            <div>
                <form method="Post" action="ViewWarehouse" id="next"> 

                    <input type="hidden" name="pageNumber" id="pageNumber" size="50" value="${pageNumber}"/>
                    <input type="hidden" name="numberOfPages" id="numberOfPages" size="50" value="${numberOfPages}"/>

                    <div id="line_button1"> <button style="width: 60px;" type="submit" onclick="prevPage()"> << </button> 
                    </div>
                    <div id="line_button1"><input  name="pageNumber" id="pageNumber" size="1" value="${pageNumber}"/> </div>
                    <div id="line_button1"> <button style="width: 60px;" type="submit" type="submit" onclick="nextPage()"> >> </button> </div>
                </form>
            </div>
        </div>
                       <div id="footer">
                                <p>  &#169;All rights reserved</p>
                            </div>
    </body>
</html>
